﻿namespace Sai.Test.Reporting
{
	using Sai.Core.Reporting;
	using Xunit;

	public class TagContentReplacerFacts
	{
		public class TheReplaceWithMethod
		{
			[Fact]
			[Trait("Category", "Fast")]
			public void Html_Content_Existing_Tag_Content_Is_Replaced()
			{
				string originalContent = "<html><head><style type=\"text/css\">html { background-color:#fff;}</style></head><body></body></html>";

				var replacer = new TagContentReplacer("style");

				var replacedContent = replacer.ReplaceWith(originalContent, "html { background-color:#000;}");

				Assert.Contains("#000;", replacedContent);
				Assert.DoesNotContain("#fff;", replacedContent);
				Assert.Contains("<html><head><style type=\"text/css\">", replacedContent);
				Assert.Contains("</style></head><body></body></html>", replacedContent);
			}

			[Fact]
			[Trait("Category", "Fast")]
			public void Html_Content_Missing_Tag_Content_Is_Untouched()
			{
				string originalContent = "<html><head><style type=\"text/css\">html { background-color:#fff;}</style></head><body></body></html>";

				var replacer = new TagContentReplacer("p");

				var replacedContent = replacer.ReplaceWith(originalContent, "html { background-color:#000;}");

				Assert.Equal(originalContent, replacedContent);
			}
		}
	}
}
